package org.wisdom.exception;

import org.wisdom.vo.errorcode.IErrorCode;
import org.wisdom.vo.errorcode.impl.ErrorCode;

/**
 * 业务异常
 * 
 * @author zhangzhiyan
 * @date 2021/06/27 18:28
 **/
@SuppressWarnings("unused")
public class BusinessException extends RuntimeException {
    private final int code;
    private final String detailMessage;

    public BusinessException(int code, String message) {
        super(message);
        this.code = code;
        this.detailMessage = message;
    }

    /**
     * 业务异常
     * 
     * @author zhangzhiyan
     * @date 2021/06/27 18:41
     * @param errorCode
     *            系统定义异常码
     */
    public BusinessException(IErrorCode errorCode) {
        this(errorCode.getCode(), errorCode.getMsg());
    }

    /**
     * 业务异常
     * 
     * @author zhangzhiyan
     * @date 2021/06/27 18:39
     * @param message
     *            自定义业务异常消息
     */
    public BusinessException(String message) {
        this(ErrorCode.BUSINESS_ERROR.getCode(), message);
    }

    /**
     * 获取异常码
     * 
     * @author zhangzhiyan
     * @date 2021/08/04 16:03
     * @return int 异常码
     */
    public int getCode() {
        return code;
    }

    /**
     * 重写获取异常信息方法
     * 
     * @author zhangzhiyan
     * @date 2021/06/27 19:04
     * @return java.lang.String
     */
    @Override
    public String getMessage() {
        return detailMessage;
    }
}
